<template>
  <div class="container">

    <div v-for="(item,index) in data " :key="index">

      <!--    单选题-->
      <div v-if="item.type == '单选题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div>{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 70px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item" v-for="(itemDan,indexDan) in 6" :key="indexDan">
                <el-radio v-if="indexDan == 0" disabled v-model="item.select" label="A">A.{{ item.A }}</el-radio>
                <el-radio v-if="indexDan == 1" disabled v-model="item.select" label="B">B.{{ item.B }}</el-radio>
                <el-radio v-if="indexDan == 2" disabled v-model="item.select" label="C">C.{{ item.C }}</el-radio>
                <el-radio v-if="indexDan == 3" disabled v-model="item.select" label="D">D.{{ item.D }}</el-radio>
                <el-radio v-if="indexDan == 4 && item.E != '' " disabled v-model="item.select" label="E">
                  E.{{ item.E }}
                </el-radio>
                <el-radio v-if="indexDan == 5 && item.F != '' " disabled v-model="item.select" label="F">
                  F.{{ item.F }}
                </el-radio>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left">
                <span>正确答案</span>：<span>{{ getAnswer(item.dan) }}</span>
              </div>
              <div class="container-dan-answer-right">
                <div v-if="item.select == getAnswer(item.dan)" style="color: green">
                  <span>得分</span>：<span class="answer-score">{{ item.score }}</span>
                </div>
                <div v-if="item.select != getAnswer(item.dan)" style="color: red">
                  <span>得分</span>：<span class="answer-score">0</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->


      <!--    多选题-->
      <div v-if="item.type == '多选题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div v-for="(t,i) in 1" :key="i" class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div>{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 70px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item" v-for="(itemDduo,indexDduo) in 6" :key="indexDduo">
                <el-checkbox-group :value="stringToArray(item.select)">
                  <el-checkbox v-if="indexDduo === 0" disabled label="A">A.{{ item.A }}</el-checkbox>
                  <el-checkbox v-if="indexDduo === 1" disabled label="B">B.{{ item.B }}</el-checkbox>
                  <el-checkbox v-if="indexDduo === 2" disabled label="C">C.{{ item.C }}</el-checkbox>
                  <el-checkbox v-if="indexDduo === 3" disabled label="D">D.{{ item.D }}</el-checkbox>
                  <el-checkbox v-if="indexDduo === 4 && item.E != '' " disabled label="E">E.{{ item.E }}</el-checkbox>
                  <el-checkbox v-if="indexDduo === 5 && item.F != '' " disabled label="F">F.{{ item.F }}</el-checkbox>
                </el-checkbox-group>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left">
                <span>正确答案</span>：<span>{{ getAnswer(item.duo) }}</span>
              </div>
              <div class="container-dan-answer-right">
                <div v-if="item.select == getAnswer(item.duo)" style="color: green">
                  <span>得分</span>：<span class="answer-score">{{ item.score }}</span>
                </div>
                <div v-if="item.select != getAnswer(item.duo)" style="color: red">
                  <span>得分</span>：<span class="answer-score">0</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->

      <!--    判断题-->
      <div v-if="item.type == '判断题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div v-for="(t,i) in 1" :key="i" class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div>{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 70px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item" v-for="(itemPan,indexPan) in 2" :key="indexPan">
                <el-radio v-show="indexPan == 0" disabled v-model="item.select" label="A">正确</el-radio>
                <el-radio v-show="indexPan == 1" disabled v-model="item.select" label="B">错误</el-radio>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left">
                <span>正确答案</span>：<span>{{ getAnswer(item.pan) }}</span>
              </div>
              <div class="container-dan-answer-right">
                <div v-if="item.select ==  getAnswer(item.pan)" style="color: green">
                  <span>得分</span>：<span class="answer-score">{{ item.score }}</span>
                </div>
                <div v-if="item.select != getAnswer(item.pan)" style="color: red">
                  <span>得分</span>：<span class="answer-score">0</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->

      <!--    填空题-->
      <div v-if="item.type == '填空题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div v-for="(t,i) in 1" :key="i" class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div>{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 70px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item container-dan-item-duo">
                <div class="container-dan-item-select" v-for="(itemDduo,indexDduo) in stringToArray(item.select)"
                     :key="indexDduo">
                  <span>第{{ indexDduo + 1 }}空</span>
                  <el-input style="min-width: 350px;" readonly type="textarea" :value="itemDduo"
                            placeholder="请输入内容"></el-input>
                </div>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left" style="display: flex;align-items: center;">
                <div style="width: 80px">正确答案</div>
                ：
                <div style="display:flex;flex-wrap: wrap;width: 90%">
                  <div v-for="(itemDuos,indexDuos) in stringToPwdArray(item.tian)" :key="indexDuos"
                       style="margin-right: 10px;">
                    <span style="font-size: 10px;">第{{ indexDuos + 1 }}空:<span
                      style="font-size: 18px">{{ itemDuos }}</span></span>
                  </div>
                </div>
              </div>
            </div>
            <div class="container-dan-item-jian" style="">
              <div class="container-dan-answer-right">
                <span>打分</span>：
                <el-input-number :value="getTianAnswer(item.select,item.tian,item.score)" :step="0.5" :min="0"
                                 :max="item.score"></el-input-number>
              </div>
            </div>
            <div class="container-dan-answer-right" style="font-weight: bold">
              <div v-if="getTianAnswer(item.select,item.tian,item.score) > 0" style="color: green">
                <span>得分</span>：<span class="answer-score">{{
                  getTianAnswer(item.select, item.tian, item.score)
                }}</span>
              </div>
              <div v-if="getTianAnswer(item.select,item.tian,item.score) <= 0" style="color: red">
                <span>得分</span>：<span class="answer-score">0</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->


      <!--    解答题-->
      <div v-if="item.type == '简答题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div v-for="(t,i) in 1" :key="i" class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div>{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 70px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item">
                <el-input readonly type="textarea" v-model="item.select"
                          placeholder="请输入内容"></el-input>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left">
                <span>参考答案</span>：
              </div>
            </div>
            <div class="container-dan-item">
              <div v-html="getAnswer(item.content)"></div>
            </div>
            <div class="container-dan-item-jian" style="">
              <div class="container-dan-answer-right">
                <span>打分</span>：
                <el-input-number v-model="item.point" :step="0.5" :min="0" :max="item.score"></el-input-number>
              </div>
              <div @click="similarScore(item.answer,item.content,index,item.score)"
                   style="margin-left: 20px;cursor: pointer;color: dodgerblue">
                AI算分
              </div>
            </div>
            <div v-if="item.point != 0" style="color: green">
              <span>得分</span>：<span class="answer-score">{{ item.point }}</span>
            </div>
            <div v-if="item.point == 0" style="color: red">
              <span>得分</span>：<span class="answer-score">0</span>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->


      <!--    扫码题-->
      <div v-if="item.type == '扫码题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div style="width: 35px">{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 90px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div>
              <div class="container-dan-item">
                <el-input readonly type="textarea" v-model="item.select"
                          placeholder="请输入内容"></el-input>
              </div>
              <div style="display:flex;flex-wrap: wrap;margin-left: 12px">
                <div style="margin-right: 20px" class="block" v-for="(itemS,indexS) in item.answerImage"
                     :key="indexS">
                  <el-image
                    style="width: 200px; height:200px"
                    :src="itemS"
                    fit="scale-down"
                    :preview-src-list="item.answerImage"
                  ></el-image>
                </div>
              </div>
            </div>
            <div class="container-dan-answer">
              <div class="container-dan-answer-left">
                <span>参考答案</span>：
              </div>
            </div>
            <div class="container-dan-item">
              <div v-html="getAnswer(item.content)"></div>
            </div>
            <div class="container-dan-item-jian" style="">
              <div class="container-dan-answer-right">
                <span>打分</span>：
                <el-input-number v-model="item.point" :step="0.5" :min="0" :max="item.score"></el-input-number>
              </div>
              <div @click="similarScore(item.answer,item.content,index,item.score)"
                   style="margin-left: 20px;cursor: pointer;color: dodgerblue">
                AI算分
              </div>
            </div>
            <div v-if="item.point != 0" style="color: green">
              <span>得分</span>：<span class="answer-score">{{ item.point }}</span>
            </div>
            <div v-if="item.point == 0" style="color: red">
              <span>得分</span>：<span class="answer-score">0</span>
            </div>
          </div>
        </div>
      </div>
      <!--    end-->


      <!--    阅读题-->
      <div v-if="item.type == '阅读题' " class="container-dan">
        <div class="container-dan-item-conter">
          <!--        类型-->
          <div class="container-dan-type">
            <span>{{ item.show_type }}</span>
          </div>
          <!--        end-->
          <div class="container-dan-item">
            <div class="container-dan-title">
              <div style="display: flex;align-items: center">
                <div style="width: 30px">{{ index + 1 }}</div>
                <div v-html="item.title"></div>
                <div style="width: 90px;margin-left: 10px">({{ item.score }}.0分)</div>
              </div>
            </div>
            <div style="margin-left: 20px;margin-top: 20px">
              <div v-for="(t,i) in item.json" :key="i">

                <!--              单选题-->
                <div v-if="t.type == '单选题' " style="margin-left: 10px;margin-bottom: 20px">
                  <div>
                    <div class="container-dan-title">
                      <div style="display: flex;align-items: center">
                        <div style="width: 30px">{{ i + 1 }}</div>
                        <div v-html="t.title"></div>
                        <div style="width: 90px;margin-left: 10px">({{ t.score }}.0分)</div>
                      </div>
                    </div>
                    <div class="container-dan-item" v-for="(itemDan,indexDan) in 6" :key="indexDan">
                      <el-radio v-if="indexDan == 0" disabled v-model="t.select" label="A">A.{{ t.A }}</el-radio>
                      <el-radio v-if="indexDan == 1" disabled v-model="t.select" label="B">B.{{ t.B }}</el-radio>
                      <el-radio v-if="indexDan == 2" disabled v-model="t.select" label="C">C.{{ t.C }}</el-radio>
                      <el-radio v-if="indexDan == 3" disabled v-model="t.select" label="D">D.{{ t.D }}</el-radio>
                      <el-radio v-if="indexDan == 4 && t.E != '' " disabled v-model="t.select" label="E">E.{{ t.E }}
                      </el-radio>
                      <el-radio v-if="indexDan == 5 && t.F != '' " disabled v-model="t.select" label="F">F.{{ t.F }}
                      </el-radio>
                    </div>
                  </div>
                  <div class="container-dan-answer">
                    <div class="container-dan-answer-left">
                      <span>正确答案</span>：<span>{{ t.answer }}</span>
                    </div>
                    <div class="container-dan-answer-right">
                      <div v-if="t.select == t.answer" style="color: green">
                        <span>得分</span>：<span class="answer-score">{{ t.score }}</span>
                      </div>
                      <div v-if="t.select != t.answer" style="color: red">
                        <span>得分</span>：<span class="answer-score">0</span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--              end-->

                <!--              多选题-->
                <div v-if="t.type == '多选题' " style="margin-bottom: 20px">
                  <div class="container-dan-item">
                    <div class="container-dan-title">
                      <div style="display: flex;align-items: center">
                        <div style="width: 30px">{{ i + 1 }}</div>
                        <div v-html="t.title"></div>
                        <div style="width: 90px;margin-left: 10px">({{ t.score }}.0分)</div>
                      </div>
                    </div>
                    <div>
                      <div class="container-dan-item" v-for="(itemDduo,indexDduo) in 6" :key="indexDduo">
                        <el-checkbox-group :value="stringToArray(t.select)">
                          <el-checkbox v-if="indexDduo == 0" disabled label="A">A.{{ t.A }}</el-checkbox>
                          <el-checkbox v-if="indexDduo == 1" disabled label="B">B.{{ t.B }}</el-checkbox>
                          <el-checkbox v-if="indexDduo == 2" disabled label="C">C.{{ t.C }}</el-checkbox>
                          <el-checkbox v-if="indexDduo == 3" disabled label="D">D.{{ t.D }}</el-checkbox>
                          <el-checkbox v-if="indexDduo == 4 && t.E != '' " disabled label="E">E.{{
                              t.E
                            }}
                          </el-checkbox>
                          <el-checkbox v-if="indexDduo == 5 && t.F != '' " disabled label="F">F.{{
                              t.F
                            }}
                          </el-checkbox>
                        </el-checkbox-group>
                      </div>
                    </div>
                    <div class="container-dan-answer">
                      <div class="container-dan-answer-left">
                        <span>正确答案</span>：<span>{{ t.answer.join() }}</span>
                      </div>
                      <div class="container-dan-answer-right">
                        <div v-if="t.score == t.answer.join()" style="color: green">
                          <span>得分</span>：<span class="answer-score">{{ t.score }}</span>
                        </div>
                        <div v-if="t.score != t.answer.join()" style="color: red">
                          <span>得分</span>：<span class="answer-score">0</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!--              end-->


                <!--    判断题-->
                <div v-if="t.type == '判断题' " style="margin-bottom: 20px">
                  <div class="container-dan-item">
                    <div class="container-dan-title">
                      <div style="display: flex;align-items: center">
                        <div style="width: 30px">{{ i + 1 }}</div>
                        <div v-html="t.title"></div>
                        <div style="width: 90px;margin-left: 10px">({{ t.score }}.0分)</div>
                      </div>
                    </div>
                    <div>
                      <div class="container-dan-item" v-for="(itemPan,indexPan) in 2" :key="indexPan">
                        <el-radio v-show="indexPan == 0" disabled v-model="t.select" label="A">正确</el-radio>
                        <el-radio v-show="indexPan == 1" disabled v-model="t.select" label="B">错误</el-radio>
                      </div>
                    </div>
                    <div class="container-dan-answer">
                      <div class="container-dan-answer-left">
                        <span>正确答案</span>：<span>{{ t.answer }}</span>
                      </div>
                      <div class="container-dan-answer-right">
                        <div v-if="t.select == t.answer" style="color: green">
                          <span>得分</span>：<span class="answer-score">{{ t.score }}</span>
                        </div>
                        <div v-if="t.select != t.answer" style="color: red">
                          <span>得分</span>：<span class="answer-score">0</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!--    end-->

                <!--    填空题-->
                <div v-if="t.type == '填空题' " style="margin-bottom: 20px">
                  <div class="container-dan-item">
                    <div class="container-dan-title">
                      <div style="display: flex;align-items: center">
                        <div style="width: 30px">{{ i + 1 }}</div>
                        <div v-html="t.title"></div>
                        <div style="width: 90px;margin-left: 10px">({{ t.score }}.0分)</div>
                      </div>
                    </div>
                    <div>
                      <div class="container-dan-item container-dan-item-duo">
                        <div class="container-dan-item-select" v-for="(itemDduo,indexDduo) in stringToArray(t.select)"
                             :key="indexDduo">
                          <span>第{{ indexDduo + 1 }}空</span>
                          <el-input style="min-width: 350px;" readonly type="textarea" :value="itemDduo"
                                    placeholder="学生未答题"></el-input>
                        </div>
                      </div>
                    </div>
                    <div class="container-dan-answer">
                      <div class="container-dan-answer-left" style="display: flex;align-items: center;">
                        <div style="width: 80px">正确答案</div>
                        ：
                        <div style="display:flex;flex-wrap: wrap;width: 90%">
                          <div v-for="(itemDuos,indexDuos) in stringToArray(t.answer)" :key="indexDuos"
                               style="margin-right: 10px;">
                    <span style="font-size: 10px;">第{{ indexDuos + 1 }}空:<span
                      style="font-size: 18px">{{ itemDuos }}</span></span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="container-dan-item-jian" style="">
                      <div class="container-dan-answer-right">
                        <span>打分</span>：
                        <el-input-number v-model="t.point" :step="0.5" :min="0"
                                         :max="t.score"></el-input-number>
                      </div>
                    </div>
                    <div class="container-dan-answer-right" style="font-weight: bold">
                      <div v-if="t.point > 0" style="color: green">
                        <span>得分</span>：<span
                        class="answer-score">{{ t.point }}</span>
                      </div>
                      <div v-if="t.point <= 0" style="color: red">
                        <span>得分</span>：<span class="answer-score">0</span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--    end-->


                <!--    解答题-->
                <div v-if="t.type == '简答题' " style="margin-bottom: 20px">
                  <div class="container-dan-item">
                    <div class="container-dan-title">
                      <div style="display: flex;align-items: center">
                        <div style="width: 30px">{{ i + 1 }}</div>
                        <div v-html="t.title"></div>
                        <div style="width: 90px;margin-left: 10px">({{ t.score }}.0分)</div>
                      </div>
                    </div>
                    <div>
                      <div class="container-dan-item">
                        <el-input readonly type="textarea" v-model="t.select"
                                  placeholder="未做答题"></el-input>
                      </div>
                    </div>
                    <div class="container-dan-answer">
                      <div class="container-dan-answer-left">
                        <span>参考答案</span>：
                      </div>
                    </div>
                    <div class="container-dan-item">
                      <div v-html="t.answer"></div>
                    </div>
                    <div class="container-dan-item-jian" style="">
                      <div class="container-dan-answer-right">
                        <span>打分</span>：
                        <el-input-number v-model="t.point" :step="0.5" :min="0" :max="t.score"></el-input-number>
                      </div>
                    </div>
                    <div v-if="t.point != 0" style="color: green">
                      <span>得分</span>：<span class="answer-score">{{ t.point }}</span>
                    </div>
                    <div v-if="t.point == 0" style="color: red">
                      <span>得分</span>：<span class="answer-score">0</span>
                    </div>
                  </div>
                </div>
                <!--    end-->
              </div>


            </div>
          </div>
        </div>
      </div>
      <!--    end-->


    </div>
    <div style="margin-top: 20px;text-align: center">
      <el-button @click="scoreSum" type="primary">计算分数</el-button>
      <el-button @click="MarkingPapers" type="success">保存</el-button>
      <div style="font-weight: bold;margin-top: 10px">
        当前总分数为 {{ manual + ai }} 分, 其中机改分数：{{ ai }},
        人工阅卷：{{ manual }}
      </div>
    </div>
  </div>
</template>

<script>
import crypto from "../../../../utils/crypto";

export default {
  props: {
    examData: {
      type: String,
      default: String
    },
    baseData: {
      type: Object,
      default: Object
    }
  },
  data() {
    return {
      manual: 0,// 人工阅卷分数
      ai: 0,//机器批阅分数
      data: []
    }
  },

  watch: {
    examData: {
      handler: function (newVal) {
        if (newVal) {
          let data = JSON.parse(newVal);
          data.forEach(item => {
            if (item.type == '单选题') {
              if (item.select == this.getAnswer(item.dan)) {
                item.point = item.score;
              } else {
                item.point = 0;
              }
            }
            if (item.type == '判断题') {
              if (item.select == this.getAnswer(item.pan)) {
                item.point = item.score;
              } else {
                item.point = 0;
              }
            }
            if (item.type == '多选题') {
              if (item.select) {
                if (Array.isArray(item.select)) {
                  item.select = item.select.sort().join();
                }
                if (item.select == this.getAnswer(item.duo)) {
                  item.point = item.score;
                } else {
                  item.point = 0;
                }
              } else {
                item.point = 0;
              }
            }
            if (item.type == '填空题') {
              if (item.select) {
                if (this.getTianAnswer(item.select, item.tian, item.score) > 0) {
                  item.point = this.getTianAnswer(item.select, item.tian, item.score);
                } else {
                  item.point = 0;
                }
              } else {
                item.point = 0;
              }
            }

            if (item.type == '阅读题') {
              if (item.json) {
                item.json.forEach(t => {
                  if (t.type == '单选题') {
                    if (t.select == t.answer) {
                      t.point = t.score;
                    } else {
                      t.point = 0;
                    }
                  }
                  if (t.type == '判断题') {
                    if (t.select == t.answer) {
                      t.point = t.score;
                    } else {
                      t.point = 0;
                    }
                  }
                  if (t.type == '多选题') {
                    if (t.select) {
                      if (Array.isArray(t.select)) {
                        t.select = t.select.sort().join()
                      }
                      if (t.select == t.answer) {
                        t.point = t.score;
                      } else {
                        t.point = 0;
                      }
                    } else {
                      t.point = 0;
                    }
                  }
                  if (t.type == '填空题') {
                    if (t.select) {
                      if (this.getJsonTianAnswer(t.select, t.answer, t.score) > 0) {
                        t.point = this.getJsonTianAnswer(t.select, t.answer, t.score);
                      } else {
                        t.point = 0;
                      }
                    } else {
                      t.point = 0;
                    }
                  }

                })
              }
            }

          })
          this.data = data;
        }
      },
      immediate: true,
      deep: true
    }

  },

  methods: {

    getAnswer: function (val) {
      if (val) return crypto.decrypt(val);
    },


    /**
     * 填空算分处理
     * @param select 用户选择答案
     * @param answer 系统答案
     * @param score 本题分数
     */
    getTianAnswer: function (select, answer, score) {
      if (select) {
        let answerSum = 0;//做对个数
        let ans = this.getAnswer(answer).split(',');
        ans.forEach((item, index) => {
          if (select[index] == item) {
            answerSum++
          }
        })
        if (ans.length > 0) {
          return answerSum / ans.length * score
        }

      }
      return 0;
    },

    getJsonTianAnswer: function (select, answer, score) {
      if (select) {
        let answerSum = 0;//做对个数
        let ans = answer.split(',');
        ans.forEach((item, index) => {
          if (select[index] == item) {
            answerSum++
          }
        })
        if (ans.length > 0) {
          return (answerSum / ans.length * score).toFixed(2);
        }

      }
      return 0;
    },

    /**
     * 计算总分
     */
    scoreSum: function () {
      let sum = 0;
      let ai = 0;//机器算分
      let manual = 0 //手工算分
      try {
        this.data.forEach((item, index) => {
          if (
            item.type == '单选题'
            || item.type == '多选题'
            || item.type == '判断题'
            || item.type == '填空题'
          ) {
            if (item.point > 0) {
              ai += item.point
            }
          }

          if (item.type == '简答题' || item.type == '扫码题') {
            if (item.point == undefined) {
              throw new Error(`第${index + 1}题未批阅！`)
            }

            if (item.point > 0) {
              manual += item.point;
            }
          }

          if (item.type == '阅读题') {
            item.json.forEach((t, i) => {
              if (t.type == '单选题' || t.type == '多选题' || t.type == '判断题' || t.type == '填空题') {
                if (t.point > 0) {
                  ai += t.point
                }
              }

              if (t.type == '简答题') {

                if (t.point == undefined) {
                  throw new Error(`第${index + 1}大题：第${i + 1}小题未批阅！`)
                }
                if (t.point > 0) {
                  manual += t.point;
                }
              }
            })
          }

        })
      } catch (e) {
        this.$message.error(e);
        return -1;
      }
      this.ai = ai;
      this.manual = manual;
      return 1;
    },

    /**
     * 点击保存批阅试卷
     * @constructor
     */
    MarkingPapers: function () {
      if (this.scoreSum() == -1) {
        return;
      }
      this.$store
        .dispatch("exam/MarkingPapers", {
          id: this.baseData['id'],
          robot_score: this.ai,
          school_score: this.manual,
          content: JSON.stringify(this.data),
        })
        .then((res) => {
          const {data, msg} = res;
          if (data) {
            this.$emit("refreshData")
            this.$message.success(msg);
            return;
          }
          return this.$message.error(msg);
        });
    },

    stringToJson: function (val) {
      if (!val) return 0;
      return JSON.parse(val);
    },
    stringToArray: function (val) {
      if (!val) return 0;
      if (Array.isArray(val)) return val;
      return val.split(',');
    },
    stringToPwdArray: function (val) {
      if (!val) return 0;
      if (Array.isArray(val)) return val;
      return crypto.decrypt(val).split(',');
    },

    similarScore: function (answer, content, index, score) {
      this.data[index].point = (((this.similar(answer, content, 2)) / 10) * score / 10).toFixed(1)
    },

    /**
     * 相似度对比
     * @param s 文本1
     * @param t 文本2
     * @param f 小数位精确度，默认2位
     * @returns {string|number|*} 百分数前的数值，最大100. 比如 ：90.32
     */
    similar(s, t, f) {
      if (!s || !t) {
        return 0
      }
      if (s === t) {
        return 100;
      }
      let l = s.length > t.length ? s.length : t.length
      let n = s.length
      let m = t.length
      let d = []
      f = f || 2
      let min = function (a, b, c) {
        return a < b ? (a < c ? a : c) : (b < c ? b : c)
      }
      let i, j, si, tj, cost
      if (n === 0) return m
      if (m === 0) return n
      for (i = 0; i <= n; i++) {
        d[i] = []
        d[i][0] = i
      }
      for (j = 0; j <= m; j++) {
        d[0][j] = j
      }
      for (i = 1; i <= n; i++) {
        si = s.charAt(i - 1)
        for (j = 1; j <= m; j++) {
          tj = t.charAt(j - 1)
          if (si === tj) {
            cost = 0
          } else {
            cost = 1
          }
          d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
        }
      }
      let res = (1 - d[n][m] / l) * 100
      return res.toFixed(f)
    }

  },
  created() {

  }
}
</script>

<style scoped lang="scss">
.container {
  height: 68vh;
  overflow-y: scroll;

  .container-dan {
    margin-bottom: 20px;

    .container-dan-item-conter {

      .container-dan-type {
        text-align: center;
        line-height: 40px;
        font-weight: bold;
        color: black;
        font-size: 18px;
        height: 40px;
        background-color: #e0e9f5;
      }

      .container-dan-item-jian {
        display: flex;
        align-items: center;
        background-color: #f8f9fa;
        padding: 10px;
        justify-content: space-between
      }

      .container-dan-item-duo {
        display: flex;
        flex-wrap: wrap;

        .container-dan-item-select {
          margin-left: 16px;
          margin-bottom: 10px;
        }
      }

      .container-dan-item {
        padding: 10px;

        .container-dan-title {
          :nth-child(1) {
            color: black;
            font-weight: bold;
          }

          :nth-child(2) {
            margin-left: 20px;
            color: grey;
            font-weight: bold;
          }
        }

      }

      .container-dan-answer {
        .container-dan-answer-left {
          color: black;
          font-weight: bold;
          margin-right: 20px;
        }

        .container-dan-answer-right {
          .answer-score {
            font-size: 16px;
          }

          color: black;
          font-weight: bold;
        }

        display: flex;
      }
    }

  }
}
</style>
